import gdstk

# The GDSII file is called a library, which contains multiple cells.
lib = gdstk.Library()

# Geometry must be placed in cells.
cell = lib.new_cell("FIRST")
cell.set_property("cell-list",["str1", 8, 6.0])
cell.set_property("cell-str","str2")
cell.set_property("cell-int", 2)
cell.set_property("cell-double", 3.0)

# Create a polygon from a list of vertices
points = [(0, 0), (2, 2), (2, 6), (-6, 6), (-6, -6), (-4, -4), (-4, 4), (0, 4)]
poly = gdstk.Polygon(points)
poly.set_property("poly-list",["str3", 8, 6.0])
poly.set_property("poly-str","str4")
poly.set_property("poly-int", 2)
poly.set_property("poly-double", 3.0)
cell.add(poly)

# Create the geometry (a single rectangle) and add it to the cell.
rect = gdstk.rectangle((0, 0), (2, 1))
rect.set_property("rect-list",["str3", 8, 6.0])
rect.set_property("rect-str","str4")
rect.set_property("rect-int", 2)
rect.set_property("rect-double", 3.0)

cell.add(rect)


# Label centered at (1, 3)
label = gdstk.Label("Sample label", (5, 3), texttype=2)
label.set_property("label-list",["str3", 8, 6.0])
label.set_property("label-str","str4")
label.set_property("label-int", 2)
label.set_property("label-double", 3.0)
cell.add(label)


ref_cell= lib.new_cell("ref_cell")
ref_cell.add(rect) 
ref_cell.add(label) 

ref = gdstk.Reference(ref_cell, (1,2), 1.5, 2, True, 2,2)
ref.set_property("ref-list",["str3", 8, 6.0])
ref.set_property("ref-str","str4")
ref.set_property("ref-int", 2)
ref.set_property("ref-double", 3.0)

cell.add(ref)

# Save the library in a GDSII or OASIS file.
lib.write_gds("../../../../../build/x64-debug/bin/first.gds")
lib.write_oas("../../../../../build/x64-debug/bin/first.oas")

# Optionally, save an image of the cell as SVG.
# cell.write_svg("first.svg")